package com.zwh.modules.scheduler;

import org.quartz.Scheduler;
import org.quartz.spi.JobFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

@Configuration
public class SchedulerConfig {

    @Bean
    public MyJobFactory jobFactory(ApplicationContext applicationContext){
        MyJobFactory jobFactory= new MyJobFactory();
        jobFactory.setApplicationContext(applicationContext);
        return jobFactory;
    }

    @Bean
    @Qualifier("schedulerFactoryBean")
    public SchedulerFactoryBean schedulerFactoryBean(MyJobFactory jobFactory) {
        SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
        schedulerFactoryBean.setJobFactory(jobFactory);
        // 延时启动，应用启动1秒后
        schedulerFactoryBean.setStartupDelay(1);
        return schedulerFactoryBean;
    }

    /*@Bean
    public Scheduler scheduler(MyJobFactory jobFactory) {
        return schedulerFactoryBean(jobFactory).getObject();
    }*/

}
